/*
 *  Copyright (C) 2011  Clint Priest
 *
 *  This file is part of Snap Graph.
 *
 *  Snap Graph is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Snap Graph is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Snap Graph.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/* Browser is only loaded for the browser overlay */

LoadScript('chrome://SnapGraph/content/Browser/DataElementsLasso.js');
LoadScript('chrome://SnapGraph/content/Browser/UserSelection.js');
LoadScript('chrome://SnapGraph/content/Browser/GraphWindow.js');

var Browser = new (Class.create({
	GraphWindows: [ ],
	
	initialize: function() {
		this.PanelContainer = document.getElementById('content').mPanelContainer;

		this.Lasso = new DataElementsLasso();
		this.PanelContainer.addEventListener('DataElementLasso:SelectionMade', this.OnLassoSelectionMade.bind(this), false);
		
		document.addEventListener('DOMContentLoaded', function() {
			var wnd = new GraphWindow();
			var us = new UserSelection();
			us.SelectedElements = [].concat( /*$('Delivered').up().select('TD'), */$('RPC').up().select('TD'), $('CPM').up().select('TD') );
			wnd.AddSelection(us);
			wnd.show(300, 400);
		}.bind(this), false);
	},
	
	OnLassoSelectionMade: function(e) {
		var wnd = new GraphWindow();
		console.log(e.UserSelection);
		wnd.AddSelection(e.UserSelection);
		wnd.show(100, 100);
		
		this.GraphWindows.push(wnd);
	},
} ))();
